<template>
  <div class="box">{{ a }} + {{ b }}</div>
  <DatePicker :options="options"></DatePicker>
  <Row>
    <Button type="default" @click="add">操作</Button>
  </Row>
  <Row>
    <Col>
      {{ isAllSelected }}
      <div class="box" v-for="(item, index) in list" @click="onSelect(item)" :key="index">{{ item.name }} : {{ item.selected }}</div>
    </Col>
  </Row>
</template>
<script>
import { random, differenceBy, pick, keys } from 'lodash'
import moment from 'moment'
export default {
  data() {
    return {
      a: 1,
      b: 2,
      options: {
        shortcuts: [
          {
            text: '今天',
            value() {
              return new Date()
            }
          },
          {
            text: '明天',
            value() {
              return new Date()
            }
          },
          {
            text: '后天',
            value() {
              return new Date()
            }
          }
        ]
      },
      list: [
        {
          name: 1
        },
        {
          name: 2
        },
        {
          name: 3
        }
      ],
      isAllSelected: false,
      defaultObj: {
        a: 1,
        b: 2,
        c: 3
      },
      needToPickObj: {
        a: 99,
        b: 100,
        d: 999
      }
    }
  },
  watch: {
    list: {
      handler(newValue) {
        let isAllSelected = newValue.every((res) => res.selected)
        this.isAllSelected = isAllSelected
      },
      deep: true
    }
  },
  methods: {
    onSelect(item) {
      item.selected = !item.selected
    },
    add() {
      console.log(`helloworld`)
      this.a++
    },
    validateIdCard(idCard) {
      // 基本格式检查
      if (!idCard) return false

      // 18位身份证号码格式检查
      const reg = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
      if (!reg.test(idCard)) {
        return false
      }

      // 校验码计算
      const weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
      const checkCode = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
      let sum = 0
      for (let i = 0; i < 17; i++) {
        sum += parseInt(idCard.charAt(i)) * weight[i]
      }
      const checkDigit = checkCode[sum % 11]
      const lastDigit = idCard.charAt(17).toUpperCase()

      return checkDigit === lastDigit
    }
  },
  mounted() {
    const set = new Set([1, 1, 2, 2, 23333, 33])
    console.log(set)
    const map = new Map()
    map.set(1, 11)
    map.set(2, 22)
    let res = map.set(1, 99)
    console.log(map, res, 1)
    let a = 1
    if (a == 1 && (a = 2)) {
      console.log('a', a)
    }
    const val1 = [1, 2, 3, 4]
    const val2 = Object.entries({ a: 1, b: 2 })
    console.log(`helloworld`)

    const val3 = [...val2, ...val1]
    console.log(val3)

    const rand1 = random(1, 2)
    console.log(`rand1`, rand1)

    let result = _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)
    console.log(result)

    let r1 = _.uniq([1, 2, 3, 4, 5, 5, 5, 56, 6])
    console.log(r1)

    let r2 = _.uniqBy([{ name: 1 }, { name: 2 }, { name: 3 }, { name: 4 }, { name: 1 }], 'name')
    console.log(r2)

    let d1 = new Date().setHours(0, 0, 0, 0)
    console.log(d1)
    let d2 = +moment().hours(0).minutes(0).seconds(0).milliseconds(0)
    console.log(d1 === d2, d1, d2)

    const { a: newA, b, d } = this.needToPickObj
    const newAObj = { newA, b, d: d == 1 ? 0 : 2 }
    const pickObj = pick(this.needToPickObj, keys(this.defaultObj))
    console.log(pickObj, newAObj)
    let obj = {
      a: 1,
      b: 2,
      c: 'abc'
    }
    console.log(obj)
  }
}
</script>
<style lang="scss" scoped>
.box {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
}
</style>
